import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import SideBar from '../component/sideBar/SideBar';
import { listenDrag, loadChildTree } from '../actions/init';

class SideBarContainer extends React.Component {
  componentDidMount() {
    const {
      listenDrag,
    } = this.props;
    listenDrag();
  }
  componentWillReceiveProps(nextProps) {
    // console.log(nextProps);
  }

  render() {
    return (
      <SideBar
        {...this.props}
      />
    );
  }
}

function mapStateToProps(state) {
  const { folderTree, jsonTree, filterTag } = state.main;
  return {
    folderTree,
    jsonTree,
    filterTag
  };
}

function mapDispatchToProps(dispatch) {
  return bindActionCreators({
    listenDrag,
    loadChildTree,
  }, dispatch);
}

export default connect(mapStateToProps, mapDispatchToProps)(SideBarContainer);
